﻿using System.ComponentModel;

namespace CSW.Framework.Common.Binding
{
    /// <summary>
    /// IChildListProperty
    /// </summary>
    public interface IChildListProperty
    {
        /// <summary>
        /// Refreshes this instance.
        /// </summary>
        void Refresh();

        /// <summary>
        /// Gets the unsafe value.
        /// </summary>
        /// <value>The unsafe value.</value>
        object UnsafeValue { get; }

        /// <summary>
        /// Gets the name of the property.
        /// </summary>
        /// <value>The name of the property.</value>
        string PropertyName { get; }

        /// <summary>
        /// Gets the value.
        /// </summary>
        /// <value>The value.</value>
        IBindingList Value { get; }

        /// <summary>
        /// Tries to save the record's current state as its baseline state.
        /// </summary>
        /// <returns><c>true</c> if successful; otherwise, <c>false</c>.</returns>
        bool TrySaveBaselineState(out string errorMessage);

        /// <summary>
        /// Reverts the object to its baseline state.
        /// </summary>
        void RevertToBaselineState();

        /// <summary>
        /// Returns <c>true</c> if the detail list has changes.
        /// </summary>
        /// <returns><c>true</c> if the detail list has changes; otherwise, <c>false</c>.</returns>
        bool GetDetailListHasChanges();

        /// <summary>
        /// Tries to save the record to the database. It is this method's responsibility to <see cref="BindableObject.CheckAllRules(out string)"/> and set <see cref="BusinessObject.IsEditting"/> to false.
        /// </summary>
        /// <param name="errorMessage">The error message.</param>
        /// <returns><c>true</c> if successful; otherwise, <c>false</c>.</returns>
        bool TrySave(out string errorMessage);

        /// <summary>
        /// Gets a value indicating whether this instance is initialized.
        /// </summary>
        /// <value><c>true</c> if this instance is initialized; otherwise, <c>false</c>.</value>
        bool IsInitialized { get; }
    }
}
